/*
 * @Description: file content
 * @Author: oooh
 * @Date: 2024-05-08 10:06:25
 * @LastEditors: oooh
 * @LastEditTime: 2024-05-08 10:16:09
 * @FilePath: \Civil_Servant_Performance_PC\src\utils\dept.js
 */

// 处理树形结构数据children为空数据
export function removeEmptyChildren(treeData) {
  for (let i = 0; i < treeData.length; i++) {
    const node = treeData[i]

    // 检查节点是否有 children 属性
    if (node.children) {
      // 递归处理每个子节点
      node.children = removeEmptyChildren(node.children)

      // 如果处理完之后 children 属性为空数组，则删除 children 属性
      if (node.children.length === 0) {
        delete node.children
      }
    }
  }
  return treeData
}
